<?php


namespace app\admin\controller\admin;


use app\common\controller\Backstage;
use hg\apidoc\annotation as Apidoc;
use thans\jwt\facade\JWTAuth;
use think\facade\Db;

/**
 * @Apidoc\Title("首页相关")
 */
class Index extends Backstage
{
    //中间件不验证的方法
    protected $middleware = [
        'app\\middleware\\Admin' => [
            'except' => ['roleApi']
        ]
    ];

    /**
     * @Apidoc\Title("左侧栏目")
     * @Apidoc\Url("/admin/admin.index/roleApi")
     * @Apidoc\Method("POST")
     * @Apidoc\Returned("data", type="array", desc="返回说明")
     */
    public function roleApi(){
        try {
        $result = JWTAuth::auth();//token验证
        $admin_id = $result['admin_id'];
        $admin = Db::name("admin")
            ->where(['id' => $admin_id])
            ->field(['id', 'role_id', 'avatar', 'name'])
            ->find();
        $admin['avatar'] = get_file_url($admin['avatar']);
        $role_list = $this->roleList($admin['role_id']);
        } catch (\Exception $e) {
            // 验证失败 输出错误信息
            return $this->ajax(-5, '登录失效');
        }
        return $this->ajax(1, "成功", [
            'list' => $role_list,
            'admin' => $admin,
        ]);
    }
}
